<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
	<title>项目设计工时统计</title>
	<script type="text/javascript" src="../../js/boot.js"></script>
</head>

<body>

	<fieldset id="fd1" style="width: 97%; margin-bottom: 4px;">
		<legend><span>查询条件</span></legend>
		<div id="queryForm" class="fieldset-body">
			<table class="form-table" border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td class="form-label">
						<span>项目：</span>
						<div id="projectID" name="projectID" class="mini-combobox" style="width:300px;" popupWidth="300" textField="projectName"
							valueField="projectID" showClose="true" oncloseclick="onCloseClick">
							<div property="columns">
								<div header="项目编号" field="projectNo"></div>
								<div header="项目名称" field="projectName"></div>
							</div>
						</div>
						<span>日期从：</span>
						<input id="calendarDate_from" name="calendarDate_from" class="mini-datepicker" format="yyyy-MM-dd" style="width: 150px" />
						<span>到：</span>
						<input id="calendarDate_to" name="calendarDate_to" class="mini-datepicker" format="yyyy-MM-dd" style="width: 150px" />
						<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-search" onclick="doSearch()">查询</a>
						<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-save" onclick="output()">导出</a>
					</td>
				</tr>
			</table>
		</div>
	</fieldset>

	<div class="mini-fit">
		<div id="datagrid" class="mini-datagrid" style="width:100%;height:100%;" pageSize="20" allowResize="true" multiSelect="true">
		</div>
	</div>

</body>

<script type="text/javascript">
	miniInit();

	// 项目名称控件数据
	var projectCombox = mini.get("projectID");
	var projectUrl = "/oa/project/project/list.do?orderBy=projectNo";
	http.get(projectUrl, function (page) {
		if (page.data.length > 0) {
			projectCombox.setData(page.data);
		}
	});

	// 设置截止日期至今天
	var date = new Date();
	mini.get("calendarDate_to").setValue(date);
	date.setDate(date.getDate() - 5);
	mini.get("calendarDate_from").setValue(date);

	var queryForm = new mini.Form("#queryForm");
	var datagrid = mini.get("datagrid");
	datagrid.set({
		columns: [
			{ type: "indexcolumn" },
			{ width: 60, headerAlign: "center", field: "projectNo", header: "项目编号" },
			{ width: 160, headerAlign: "center", field: "projectName", header: "项目名称" },
			{ width: 60, headerAlign: "center", field: "departName", header: "部门名称" }
		]
	});


	function doSearch() {
		miniui.mask("数据加载中...");
		var data = queryForm.getData(true, false);
		http.post("/project/static/project/design/work.do", data, function (page) {
			if (page.success) {
				debugger
				var columns = [
					{ type: "indexcolumn" },
					{ width: 60, headerAlign: "center", field: "projectNo", header: "项目编号" },
					{ width: 160, headerAlign: "center", field: "projectName", header: "项目名称" },
					{ width: 100, headerAlign: "center", field: "departName", header: "部门名称" }
				];
				var ids = page.dataMap.id;
				var names = page.dataMap.name;
				for (var i = 0; i < ids.length; i++) {
					columns.push({ width: 60, headerAlign: "center", field: ids[i], header: names[i] });
				}
				datagrid.set({
					columns
				});
				datagrid.setData(page.data);
			} else {
				miniui.showLoadErrorMessageBox(page.message);
			}
			mini.unmask();
		});
	}

	function output() {
		mini.mask({
			el: document.body,
			cls: 'mini-mask-loading',
			html: '数据处理中...'
		});
		var data = queryForm.getData(true, false);
		// debugger
		// data["orderby"] = ["calendarDate,desc"];
		http.post("/project/static/project/design/work/output.do", data, function (page) {
			mini.unmask();
			if (page.success) {
				miniui.showInfoTip("数据处理成功，准备下载!");
				var url = http.getUrl("/file/any/getFile.do");
				jQuery('<form action="' + url + '"method=post">' + // action请求路径及推送方法
					'<input type="text" name="url" value="' + page.dataMap.filename + '"/>' + // 文件路径
					'</form>')
					.appendTo('body').submit().remove();
			} else {
				miniui.showErrorMessageBox(page.message);
			}
		});
	}
</script>

</html>